package lu.med.praxiswahl.wahlumed.client.gravtest;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableCellEditor;

import lu.med.praxiswahl.wahlumed.client.utilities.KillInterface;
import lu.med.praxiswahl.wahlumed.client.wclient.Main;

@SuppressWarnings("serial")
public class GravTestHalfCellEditor extends AbstractCellEditor implements
		TableCellEditor, KillInterface, ActionListener {

	private Component component;
	private GravTestHalfModel model;
	private String val = "";

	public GravTestHalfCellEditor(GravTestHalfModel model, Main dataManager) {
		this.model = model;
	}

	public void actionPerformed(ActionEvent e) {
	}

	public Object getCellEditorValue() {
		if (component.getClass() == JButton.class) {
			// Gibt Dummy Wert zurück
			return "";
		} else if (component.getClass() == JTextField.class) {
			JTextField jtf = (JTextField) component;
			return jtf.getText();
		}
		return "";
	}

	public Component getTableCellEditorComponent(JTable table, Object value,
			boolean isSelected, int row, int column) {
		val = (String) model.getValueAt(row, column);
		JTextField jtf = new JTextField();
		jtf.setText(val);
		if (column == 1) {
			// Datumsspalte
			jtf.setText(model.getOriginalDate(row));
		}
		//jtf.selectAll();
		component = jtf;

		return component;
	}

	public void killEditing() {
		this.cancelCellEditing();
	}
}